
package com.xy.core.util;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.beanutils.DynaBean;
import org.apache.commons.beanutils.DynaProperty;

// Referenced classes of package com.htsoft.core.util:
//            AppUtil

public class BeanUtil
{

    public BeanUtil()
    {
    }

    public static void copyNotNullProperties(Object obj, Object obj1)
        throws IllegalAccessException, InvocationTargetException
    {
        BeanUtilsBean beanutilsbean = BeanUtilsBean.getInstance();
        if(obj == null)
            throw new IllegalArgumentException("No destination bean specified");
        if(obj1 == null)
            throw new IllegalArgumentException("No origin bean specified");
        if(obj1 instanceof DynaBean)
        {
            DynaProperty adynaproperty[] = ((DynaBean)obj1).getDynaClass().getDynaProperties();
            for(int i = 0; i < adynaproperty.length; i++)
            {
                String s = adynaproperty[i].getName();
                if(beanutilsbean.getPropertyUtils().isReadable(obj1, s) && beanutilsbean.getPropertyUtils().isWriteable(obj, s))
                {
                    Object obj2 = ((DynaBean)obj1).get(s);
                    beanutilsbean.copyProperty(obj, s, obj2);
                }
            }

        } else
        if(obj1 instanceof Map)
        {
            Iterator iterator = ((Map)obj1).entrySet().iterator();
            do
            {
                if(!iterator.hasNext())
                    break;
                java.util.Map.Entry entry = (java.util.Map.Entry)iterator.next();
                String s1 = (String)entry.getKey();
                if(beanutilsbean.getPropertyUtils().isWriteable(obj, s1))
                    beanutilsbean.copyProperty(obj, s1, entry.getValue());
            } while(true);
        } else
        {
            PropertyDescriptor apropertydescriptor[] = beanutilsbean.getPropertyUtils().getPropertyDescriptors(obj1);
            for(int j = 0; j < apropertydescriptor.length; j++)
            {
                String s2 = apropertydescriptor[j].getName();
                if("class".equals(s2) || !beanutilsbean.getPropertyUtils().isReadable(obj1, s2) || !beanutilsbean.getPropertyUtils().isWriteable(obj, s2))
                    continue;
                try
                {
                    Object obj3 = beanutilsbean.getPropertyUtils().getSimpleProperty(obj1, s2);
                    if(obj3 != null)
                        beanutilsbean.copyProperty(obj, s2, obj3);
                }
                catch(NoSuchMethodException nosuchmethodexception) { }
            }

        }
    }
 
  
}
